# -*- coding: utf-8 -*-
from flask import render_template, url_for, request
from app.forms import UserForm
from app.models import User, db
import datetime
from random import randint


def userIndexView():
    userForm = UserForm()
    if request.method == "POST":
        xm = request.form.get("xm")
        nl = request.form.get("nl")
        xb = request.form.get("xb")
        lxdh = request.form.get("lxdh")
        id_rel = str(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))+str(randint(0, 10))
        user = User(id_rel=id_rel, xm=xm, nl=nl, xb=xb, lxdh=lxdh)
        db.session.add(user)
        db.session.commit()
        return "Secusess!"
    return render_template(
        "userIndex.html",
        userForm=userForm
    )


def adminIndexView():
    userForm = db.session.query(User).filter().all()
    return render_template(
        "adminIndex.html",
        userForm = userForm
    )
